package com.voxel.sense.infomsg.module.message;

import android.view.View;
import android.widget.TextView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;

import butterknife.BindView;
import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.model.db.MessageModle;
import cyy.example.com.facotry.model.push.WarningNoticeModel;

/**
 * Created by ChenYiYao on 2018/12/5.
 * des :
 */
public class MessageAdatper extends RecyclerAdapter<MessageModle> {
    @Override
    protected int getItemViewType(int position, MessageModle modle) {
        return R.layout.item_recycler_message_warning;
    }

    @Override
    protected ViewHolder<MessageModle> onCreateViewHolder(View root, int viewType) {
        return new WarnHolder(root);
    }
//    @Override
//    protected int getItemViewType(int position, MessageAdatper messageAdatper) {
//        return R.layout.item_recycler_message_warning;
//    }
//
//    @Override
//    protected ViewHolder<MessageModle> onCreateViewHolder(View root, int viewType) {
//        return new WarnHolder(root);
//    }


    public static class WarnHolder extends RecyclerAdapter.ViewHolder<MessageModle> {

        @BindView(R.id.tv_title)
        TextView tv_title;
        @BindView(R.id.tv_content)
        TextView tv_content;
        @BindView(R.id.tv_site)
        TextView tv_site;
        @BindView(R.id.tv_element)
        TextView tv_element;
        @BindView(R.id.tv_time)
        TextView tv_time;


        public WarnHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(MessageModle modle) {
            String extra = modle.getExtra();
            try {
                WarningNoticeModel data = Factory.getGson().fromJson(extra, WarningNoticeModel.class);
                tv_title.setText(modle.getTitle());
                tv_content.setText(data.getCompanyName());
                tv_site.setText("站位：" + data.getSiteName());
                tv_time.setText(String.format(Factory.app().getString(R.string.data_time),data.getTime()));
                tv_element.setText(String.format(Factory.app().getString(R.string.element_value),
                        data.getParamName(), data.getParamValue()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
